package org.yxj.storagefilemobile;

import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;

import org.yxj.lib_storage.LogUtils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 内容提供
 *
 * @author yxj  on 2024/7/9
 */
public class LearnContentResolver {

    public void init(Context context) {
        ContentResolver contentResolver = context.getContentResolver();
        Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
//        uri = ContentUris.withAppendedId(uri, 359);
        Cursor c = contentResolver.query(uri, null, null, null, null);
        if (null!=c && c.getCount()>0){
            c.moveToFirst();
            while (c.moveToNext()){
                String path = c.getString(c.getColumnIndex(MediaStore.Images.Media.DATA));
                String name = c.getString(c.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME));
                String createData = c.getString(c.getColumnIndex(MediaStore.Images.Media.DATE_ADDED));
                Date d = new Date();
                d.setTime(Long.parseLong(createData));
                SimpleDateFormat newIn = new SimpleDateFormat("yyyy年MM月dd日 hh:mm:ss");
                String time = newIn.format(d);
                LogUtils.LOG_V("[LearnContentResolver]->  = " +
                        new StringBuffer("\n")
                                .append("createData = " +time ).append("\n")
                                .append("count = " + c.getCount()).append("\n")
                                .append("path = " + path).append("\n")
                                .append("name = " + name).append("\n")
                                .append("uri = " + uri.toString()).append("\n")
                                .toString());
            }
            c.close();
        }else {
            LogUtils.LOG_V("[LearnContentResolver]->  is null");
        }
    }
}
